home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 12876 < prev    next >
Encoding:
Text File  |  1996-08-05  |  4.5 KB  |  184 lines

  1. Newsgroups: comp.lang.c,comp.lang.c++
  2. Path: lion.cs.latrobe.edu.au!boylesgj
  3. From: boylesgj@lion.cs.latrobe.edu.au (Gregary J Boyles)
  4. Subject: Linker error problem
  5. X-Nntp-Posting-Host: lion.cs.latrobe.edu.au
  6. Message-ID: <DonKM5.MAM@latcs1.lat.oz.au>
  7. Sender: news@latcs1.lat.oz.au (news)
  8. Organization: Comp.Sci & Comp.Eng, La Trobe Uni, Australia
  9. Date: Fri, 22 Mar 1996 05:01:17 GMT
  10.  
  11. I am getting a linker error as follows. Undefined symbol 
  12. Address::ThisPtrList in module address.cpp.
  13. I don't understand this non sense because it is defined
  14. as a static class member and its value is initialized.
  15. See $$$$ for definitions #### for causes of the error (if
  16. I comment out these lines then the error disappears.
  17.  
  18. // address.h
  19. #include <iostream.h>
  20.  
  21. #ifndef __ADDRESS_H
  22. #define __ADDRESS_H
  23. #define SIZE 100
  24.  
  25. #include "defines.h"
  26.  
  27. class Address
  28. {
  29.      private : int Number;
  30.            char *Street;
  31.            char *City;
  32.            int Zip;
  33.         $$$$$$   static Address *ThisPtrList[SIZE];
  34.            static unsigned int NumberInstances;
  35.            static unsigned int InstanceNumber;
  36.  
  37.      public : // Constructors
  38.           Address(int ANumber,const char *AStreet,const char *ACity,int Zip);
  39.           Address();
  40.           // Copy constructor
  41.           Address(Address& AnAddress);
  42.           // Deconstructor
  43.           ~Address();
  44.           // Operator overloads
  45.           friend ostream& operator << (ostream& OutPutStream,Address& AnAddress);
  46.           friend istream& operator >>(istream& InPutStream,Address& AnAddress);
  47.           // Functions
  48.           void Change(int ANumber,const char *AStreet,const char *ACity,int AZip);
  49.           unsigned int Address::NumberOfInstances();
  50.           void Address::DisplayAll();
  51. };
  52.  
  53. #endif
  54.  
  55.  
  56.  
  57. // address.cpp
  58.  
  59. #include "address.h"
  60. #include <string.h>
  61. #include <iostream.h>
  62.  
  63. // Data initializations
  64. unsigned int Address::NumberInstances=0;
  65.  
  66. unsigned int Address::InstanceNumber=0;
  67.  
  68. $$$$ Address Address::*ThisPtrList={0};
  69.  
  70. // Constructors
  71. Address::Address(int ANumber,const char *AStreet,const char *ACity,int AZip)
  72. {
  73.      Number=ANumber;
  74.      Street=new char[strlen(AStreet)+1];
  75.      strcpy(Street,AStreet);
  76.      City=new char[strlen(ACity)+1];
  77.      strcpy(City,ACity);
  78.      Zip=AZip;
  79. ####     ThisPtrList[NumberInstances]=this;
  80.      NumberInstances++;
  81.      InstanceNumber=NumberInstances;
  82. }
  83.  
  84. Address::Address()
  85. {
  86.      Number=0;
  87.      Street=new char[strlen("")+1];
  88.      strcpy(Street,"");
  89.      City=new char[strlen("")+1];
  90.      strcpy(City,"");
  91.      Zip=0;
  92. ####     ThisPtrList[NumberInstances]=this;
  93.      NumberInstances++;
  94.      InstanceNumber=NumberInstances;
  95. }
  96.  
  97. // Copy constructor
  98. Address::Address(Address& AnAddress)
  99. {
  100.      Number=AnAddress.Number;
  101.      Street=new char[strlen(AnAddress.Street)+1];
  102.      strcpy(Street,AnAddress.Street);
  103.      City=new char[strlen(AnAddress.City)+1];
  104.      strcpy(City,AnAddress.City);
  105.      Zip=AnAddress.Zip;
  106. ####     ThisPtrList[NumberInstances]=this;
  107.      NumberInstances++;
  108.      InstanceNumber=NumberInstances;
  109. }
  110.  
  111. // Deconstructor
  112. Address::~Address()
  113. {
  114.      Number=0;
  115.      delete Street;
  116.      delete City;
  117.      Zip=0;
  118. }
  119.  
  120. // Operator overloads
  121. ostream& operator <<(ostream& OutPutStream,Address& AnAddress)
  122. {
  123.      OutPutStream<<"Street : "<<AnAddress.Number<<" "<<AnAddress.Street<<EOLN;
  124.      OutPutStream<<"City : "<<AnAddress.City<<EOLN;
  125.      OutPutStream<<"Zip code : "<<AnAddress.Zip<<EOLN;
  126.      return(OutPutStream);
  127. }
  128.  
  129.  
  130. istream& operator >>(istream& InPutStream,Address& AnAddress)
  131. {
  132.      char *StreetName,*CityName,ch;
  133.  
  134.      StreetName=new char[50];
  135.      CityName=new char[50];
  136.      cout<<"Number : ";
  137.      cin>>AnAddress.Number;
  138.      GetEndOfLine();
  139.      cout<<"Street : ";
  140.      cin.getline(StreetName,49,EOLN);
  141.      delete AnAddress.Street;
  142.      AnAddress.Street=new char[strlen(StreetName)+1];
  143.      strcpy(AnAddress.Street,StreetName);
  144.      cout<<"City : ";
  145.      cin.getline(CityName,49,EOLN);
  146.      delete AnAddress.City;
  147.      AnAddress.City=new char[strlen(CityName)+1];
  148.      strcpy(AnAddress.City,CityName);
  149.      cout<<"City : ";
  150.      cout<<"Zip code : ";
  151.      cin>>AnAddress.Zip;
  152.      GetEndOfLine();
  153.      return(InPutStream);
  154. }
  155.  
  156. // Functions
  157. void Address::Change(int ANumber,const char *AStreet,const char *ACity,int AZip)
  158. {
  159.      Number=ANumber;
  160.      delete Street;
  161.      Street=new char[strlen(AStreet)+1];
  162.      strcpy(Street,AStreet);
  163.      delete City;
  164.      City=new char[strlen(ACity)+1];
  165.      strcpy(City,ACity);
  166.      Zip=AZip;
  167. }
  168.  
  169. unsigned int Address::NumberOfInstances()
  170. {
  171.      return(NumberInstances);
  172. }
  173.  
  174. void Address::DisplayAll()
  175. {
  176.      unsigned int Index;
  177.  
  178.      cout<<EOLN;
  179.      for (Index=0;Index<NumberInstances;Index++)
  180.      {
  181. ####      cout<<ThisPtrList[Index]<<EOLN;
  182.      }
  183. }
  184.